#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 5e5 + 10;

int n, c[N], pos[N], L[N], R[N], xl[N], xr[N], mx;
bool vis[N];
vec G[N];

void dfs(int x) {
	if(vis[x]) return; vis[x] = true;
	while(L[x] > 1 || R[x] < n) {
		bool fl = false;
		if(L[x] > 1 && xr[L[x] - 1] <= R[x]) dfs(L[x] - 1), R[x] = max(R[x], R[L[x] - 1]), L[x] = min(L[x], L[L[x] - 1]), fl = true;
		if(R[x] < n && xl[R[x] + 1] >= L[x]) dfs(R[x] + 1), L[x] = min(L[x], L[R[x] + 1]), R[x] = max(R[x], R[R[x] + 1]), fl = true;
		if(!fl) break;
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n - 1) c[i] = in, mx = max(mx, c[i]);
	rep(i, 1, n) { int cnt = in; while(cnt--) G[i].pb(in); }
	rep(i, 1, mx) pos[i] = 0; 
	rep(i, 1, n) {
		for(auto x : G[i]) pos[x] = i;
		xl[i + 1] = pos[c[i]];
	}
	rep(i, 1, mx) pos[i] = n + 1;
	per(i, n, 1) {
		for(auto x : G[i]) pos[x] = i;
		xr[i - 1] = pos[c[i - 1]];
	}
	rep(i, 1, n) L[i] = R[i] = i;
	rep(i, 1, n) dfs(i);
	//	rep(i, 1, n) cerr << xl[i] << " " << xr[i] << " " << L[i] << " " << R[i] << endl;
	int Q = in;
	while(Q--) {
		int x = in, y = in;
		puts(L[x] <= y && R[x] >= y ? "YES" : "NO");
	}
	return 0;
}
